<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class OrderEduBoolea extends Model
{
    protected $table = "sp_order_edu_boolea";
    protected $primaryKey = 'id';
    public $timestamps = false;

    //查询风控信息
    protected function getRiskData($cert_no)
    {
        $data = $this
            ->where('cert_no',$cert_no)
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    
    //商户查询风控信息
    protected function getMemberRiskData($cert_no,$member)
    {
        $data = $this
            ->where('cert_no',$cert_no)
            ->where('member_id',$member)
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加风控信息
    protected function setRiskData($result,$result2,$cert_name,$mobile,$cert_no,$eduNum)
    {
        $risk_data['cert_name'] = $cert_name;
        $risk_data['mobile'] = $mobile;
        $risk_data['cert_no'] = $cert_no;
        $risk_data['edu_num'] = $eduNum;
        $risk_data['result'] = json_encode($result);
        $risk_data['result2'] = json_encode($result2);
        
        $risk_data['start_at'] = date('Y-m-d H:i:s');
        
        //判断数据库没有才添加
        $edu = $this->where('cert_no',$cert_no)->first();
        
        $edu = $edu ? $edu->toArray() : array();
        
        if(empty($edu)){
            $this->insert($risk_data);
        }
        
        return true;
    }

    //编辑风控信息
    protected function editRiskData($cert_no,$risk_data)
    {
        $this->where('cert_no',$cert_no)->update($risk_data);

        return true;
    }

}
